记一次给家宽 DDNS 配置 ssl 双向认证

用 Let’s encrypt 配置 HTTPS


  1. 安装 certbot
1
yum install python2-certbot-dns-cloudflare
  1. 登录 Cloudflare 获取 Api Key,填入文件 /etc/letsencrypt/cloudflareapi.cfg 内
1
2
dns_cloudflare_email = 
dns_cloudflare_api_key =
  1. 签发多域名证书
1
certbot-2 certonly --cert-name ddns.example.com --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflareapi.cfg --server https://acme-v02.api.letsencrypt.org/directory -d "*.ddns.example.com" -d ddns.example.com
  1. 设置 crontab 在每天凌晨 2:30 自动续签证书
1
30 2 * * * certbot-2 renew --noninteractive && service nginx reload

自签双向认证证书


下载签发脚本,先使用 create_ca_cert.sh 签发 CA 证书,然后使用 create_client_cert.sh 签发客户端证书:

1
./create_client_cert.sh --ou 财务部 --cn 财务经理 --email cy@example.com

吊销已签发的客户端证书:

1
./revoke_cert.sh 财务经理

替换 lnmp 脚本,创建 vhost


将 /usr/bin/lnmp 替换为 lnmp

1
2
3
wget https://gist.github.com/jshensh/ae59190701bd00bc69251a99f4183422/raw/f2e4f4c9167c22557119014c223bc72be5c4bf14/lnmp -O /usr/bin/lnmp
chmod +x /usr/bin/lnmp
lnmp vhost add_ddns

脚本内第 22-23 行为域名和端口配置,需要修改

1
2
ddns_domain="ddns.example.com"
port="49527"

为屏蔽无效请求添加了第 1281 行的规则,可视情况处理

放行端口


1
2
3
iptables -I INPUT -p tcp --dport 49527 -j ACCEPT
iptables-save
service iptables restart

参考文章